# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# include patches from Archlinux AUR mingw-w64 stuff

_realname=popt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.18
pkgrel=1
pkgdesc="C library for parsing command line parameters (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/rpm-software-management/popt"
license=("MIT")
depends=("${MINGW_PACKAGE_PREFIX}-gettext")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
options=('staticlibs' 'strip')
source=(http://ftp.rpm.org/popt/releases/popt-1.x/${_realname}-${pkgver}.tar.gz
        "0001-nl_langinfo.mingw32.patch"
        "197416.all.patch"
        "217602.all.patch"
        "278402-manpage.all.patch"
        "318833.all.patch"
        "356669.all.patch"
        "get-w32-console-maxcols.mingw32.patch"
        "no-uid-stuff-on.mingw32.patch")
sha256sums=('5159bc03a20b28ce363aa96765f37df99ea4d8850b1ece17d1e6ad5c24fdc5d1'
            '33ecd8c6b99597256954763c81d90e7e65a2ddaaab3ae17c8a7769c77be0b22b'
            '309d083fba6c7ae9b6088755cc36373481b355806142485d3c9f356dd6355bce'
            'e4f9383cb4821976f513f64fc8c64e0dfadcc7c031e5cdce2bbe89fb6d9a40c4'
            '99b9b5547edfac75eddb90083e3d19c0076d25f1d3e1ad165b49af81ecad8ce9'
            'd5616778c0233e6a010995ef9b13a780fa5d7c29cf868e0c975dd2165d41d805'
            '57f48a2f683b7a06d89e8f3973afecfc488e4ec5067ddd357028753ff5dee93e'
            '9ad9dcff285cc34abca6c5b2f1f27e050134392562cdc41706d919adeb516dd4'
            '0a202a7e53348138c4c9c22e8a6aa089fc66ea105b64ec4251c3cb2ebf11ffae')

prepare() {
  cd "$srcdir/${_realname}-$pkgver"
  rm -rf po/ca.po || true
  patch -p1 -i $srcdir/0001-nl_langinfo.mingw32.patch
  patch -p1 -i $srcdir/197416.all.patch
  patch -p1 -i $srcdir/217602.all.patch
  patch -p1 -i $srcdir/278402-manpage.all.patch
  patch -p1 -i $srcdir/318833.all.patch
  patch -p1 -i $srcdir/356669.all.patch
  patch -p1 -i $srcdir/get-w32-console-maxcols.mingw32.patch
  patch -p1 -i $srcdir/no-uid-stuff-on.mingw32.patch
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}"

  cd "${srcdir}/build-${MSYSTEM}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
  install -D -m644 "${srcdir}/${_realname}-${pkgver}/COPYING" "$pkgdir${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
